package com.agricultural.machine.path;

import java.util.ArrayList;
import java.util.List;

/**
 * 直线路径策略 - 策略模式
 */
public class DirectPathStrategy implements PathStrategy {
    @Override
    public String getName() {
        return "直线路径";
    }

    @Override
    public String getDescription() {
        return "直线路径策略 - 两点之间直线路径，不考虑障碍物";
    }

    @Override
    public List<PathPoint> calculatePath(PathPoint start, PathPoint end, TerrainData terrain) {
        List<PathPoint> path = new ArrayList<>();
        path.add(start);
        
        // 计算直线上的点，每隔5个单位加一个点
        double distance = Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
        int pointCount = (int)(distance / 5) + 1;
        
        for (int i = 1; i < pointCount; i++) {
            double ratio = i / (double)pointCount;
            double x = start.x + (end.x - start.x) * ratio;
            double y = start.y + (end.y - start.y) * ratio;
            path.add(new PathPoint(x, y));
        }
        
        path.add(end);
        
        System.out.println("使用直线路径策略计算从 " + start + " 到 " + end + " 的路径");
        System.out.println("生成路径点数量: " + path.size());
        
        return path;
    }
} 